<?php

use yii\helpers\Url;

?>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-card">

            <ul class="layui-tab-title">
                <li class="layui-this">网站设置</li>
                <li>网站图片</li>
            </ul>
            <div class="layui-tab-content">

                <div class="layui-tab-item layui-show">
                    <form class="layui-form layui-form-pane" action="">
                        <?php foreach ($setting[1] as $list): ?>
                            <div class="layui-form-item">
                                <label class="layui-form-label"><?= $list['name'] ?></label>
                                <div class="layui-input-block">
                                    <input type="text" name="<?= $list['key'] ?>" data-id="<?= $list['id'] ?>"
                                           autocomplete="off" placeholder="请输入<?= $list['name'] ?>"
                                           class="layui-input settingText" value="<?= $list['val'] ?>">
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </form>
                </div>
                <div class="layui-tab-item">
                    图片
                </div>
                <input type="hidden" class="csrf-backend" name="<?= Yii::$app->request->csrfParam ?>"
                       value="<?= Yii::$app->request->csrfToken ?>">
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer') ?>
<script>
    let value = '';
    layui.config({
        base: '<?=Url::base()?>/resources/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set']);
    $('.settingText').focus(function () {
        value = $(this).val();
    });

    $('.settingText').blur(function (obj) {
        let val = $(this).val();
        let id = $(this).attr('data-id');
        if (val == value) {
            return true;
        }
        $.post('<?=Url::toRoute([$this->context->id . '/edit'])?>', {
            id: id,
            val: val,
            '_csrf-backend': '<?=Yii::$app->request->csrfToken?>'
        }, function (res) {
            if (res.status == 200) {
                layer.msg(res.msg, {icon: 6, time: 1000})
            } else {
                layer.msg(res.msg, {icon: 5, time: 1000})
            }
        }, 'json')
    })
</script>
<?php $this->endBlock() ?>
